package com.he.demo.config;

import com.he.demo.constant.Cst;
import com.he.demo.service.hello.HelloService;
import com.he.demo.service.yyt.YytService;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author heyanjing
 * date:2021-02-22 2021/2/22 0022:16:57
 */
@Configuration
public class CxfConfig {
    /**
     * 采用代理方式
     */
    @Bean
    public HelloService helloService() {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setServiceClass(HelloService.class);
        jaxWsProxyFactoryBean.setAddress(Cst.WSDL_URL_HELLO);
        return (HelloService) jaxWsProxyFactoryBean.create();
    }

    @Bean
    public YytService yytService() {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setServiceClass(YytService.class);
        jaxWsProxyFactoryBean.setAddress(Cst.WSDL_URL_YYT);
        return (YytService) jaxWsProxyFactoryBean.create();
    }

    /**
     * 采用动态工厂方式 不需要指定服务接口
     */
    @Bean
    public Client yytClient() {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client yytClient = dcf.createClient(Cst.WSDL_URL_YYT);
        return yytClient;
    }

    @Bean
    public Client helloClient() {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client helloClient = dcf.createClient(Cst.WSDL_URL_HELLO);
        return helloClient;
    }


}
